package com.learn.sb.webfluxdemo.controller;


import com.learn.sb.webfluxdemo.eitity.User;
import com.learn.sb.webfluxdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
public class UserController {

	@Autowired
	private UserService userService;

	@GetMapping("/user/{id}")
	public Mono<User> getUser(@PathVariable Long id) {
		return userService.findUserById(id.toString());
	}

	@PostMapping("/user2/{user}")
	public Flux<User> insertUser(@RequestBody User user) {
		userService.setUser(userService.getMapSize().toString(), user);

		return userService.findUserList();
	}

}
